<html>
<head>
    <title>qBase Tests</title>
    <script>imagePath='../';wrroot='../';scriptPath='../';contextPath='';</script>
    <script src="../qCore.js"></script>
    <script src="../qBase.js"></script>
    <style>
    </style>
    <script>
        function bodyLoaded(){
            basicObject_test()
        }

		Animal_StaticMembers = {
			pub_constants: {/* No not name const or it will kill IE :( */
				 MK_1: "key1"
				,MK_2: "key2"
			}
			,other: {
				 instances: []	
				,dumpInstances: function animal_st_dumpInstances(){
					var t=this,a=t.instances

					for(var i=0;i<a.length;i++)
						pc("Animal "+i+":\n"+s$.pad(qObjDump(a[i])))
				}
			}
		}

        function basicObject_test(){
            
          // Abstract Class
            var Animal = QBase.extend({
                base_constr :function Animal_base_constr(jOpt) {
                	pc(">>")
                	var t=this
                	t.inherit(Animal_StaticMembers.pub_constants)		
                    t.name = jOpt.name;
                    Animal.instances.p(t)
                    pc("<<")
                }
                ,name: ""
                
                ,meat: function() {
                    this.say("Prrrrrrrr!");
                }
                
                ,say: function(message) {
                    pc(this.name + ": " + message);
                }
            });;/*Inherit Static Members*/qObjAppend(Animal,Animal_StaticMembers.pub_constants);qObjAppend(Animal,Animal_StaticMembers.other)
          // end Animal Abstr Class
            
          // Interface Class (Not classical interface)
          // - Do not implement constructor or base_constr in this class!
          // - This class is designed only to contain extra methods to be appended to an instance of QBase using implement
            CrazyBeast_other = {
                goCrazy: function CzyBst_oth_goCrazy(e) {
                    pc("CrazyBeast ("+this.name+" the "+(oGetClassOf(this))+") said 'arrrrgggggh'");
                }
            };
            
            var Cat = Animal.extend({
                base_constr :function Cat_base_constr(jOpt) {
                	pc(">>")
                    this.name = jOpt.name;
                    this.base(jOpt)
                    pc("<<");
                }
                ,eat: function Cat_eat(food) {
                    if (food instanceof Mouse) this.base();
                    else this.say("Yuk! I only eat mice.");
                }
              /* Constructor Entry Point - Not needed for Abstract Classes */
                ,constructor: function Cat(jOpt) {pc(">>");
                    this.base_constr(jOpt)
                    pc("<<");
                }
            });
            
          // Multiple Inheritance
            Cat.implement(CrazyBeast_other)
           
            catFifi = new Cat({name: "fifi"})   
        	catFofo = new Cat({name: "fofo"})   
            
            catFifi.goCrazy()
            
          // On-thie fly instance based inheritance
            catFifi.inherit({
                goReallyCrazy: function catFifi_goReallyCrazy(e) {
                    pc("CrazyBeast ("+this.name+" the "+(oGetClassOf(this))+") said '"+this.favorateSound+"' (very loud)");
                } 
               ,favorateSound: "ARRRRGHHHHH"
            })
            
            catFifi.goReallyCrazy()
            
            pc("fofo.goReallyCrazy = "+ catFofo.goReallyCrazy)
            
            Animal.dumpInstances()
        }
        
        
        
    </script>
</head>

<body>
	<script>
        bConsole=true; __qcOpts={cb:true, t:0, w: 600, h: 800}
	    _SCR_START=" bodyLoaded();"; function __start() {try{if(bConsole){startCons(__qcOpts); _w.consoleLoaded = function consoleLoaded(){ setTimeout(_SCR_START,50) }}else{eval(_SCR_START)}}catch(e){debugErr(e)}};__start()
    </script>
</body>
</html>